package ext.generic.wfaugment.processors;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import wt.change2.WTChangeActivity2;
import wt.change2.WTChangeIssue;
import wt.change2.WTChangeOrder2;
import wt.change2.WTChangeRequest2;
import wt.doc.WTDocument;
import wt.epm.EPMDocument;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.ReferenceFactory;
import wt.fc.WTObject;
import wt.inf.container.WTContained;
import wt.inf.container.WTContainer;
import wt.inf.team.ContainerTeam;
import wt.inf.team.ContainerTeamHelper;
import wt.inf.team.ContainerTeamManaged;
import wt.inf.team.ContainerTeamReference;
import wt.maturity.PromotionNotice;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.org.WTGroup;
import wt.org.WTPrincipal;
import wt.org.WTPrincipalReference;
import wt.org.WTUser;
import wt.part.WTPart;
import wt.project.Role;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.services.Manager;
import wt.services.ManagerServiceFactory;
import wt.session.SessionHelper;
import wt.session.SessionServerHelper;
import wt.team.Team;
import wt.util.WTException;
import wt.util.WTMessage;
import wt.util.WTProperties;
import wt.vc.baseline.ManagedBaseline;
import wt.workflow.definer.ProcessStepTemplateLink;
import wt.workflow.definer.WfAssignedActivityTemplate;
import wt.workflow.definer.WfProcessTemplate;
import wt.workflow.engine.WfActivity;
import wt.workflow.engine.WfProcess;
import wt.workflow.work.WfAssignedActivity;
import wt.workflow.work.WorkItem;

import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.com.iba.IBAUtil;
import ext.com.workflow.WorkflowUtil;

public class WfAugmentServiceFwd
  implements RemoteAccess, WfAugmentService, Serializable
{
  private static boolean VERBOSE = false;
  static final boolean SERVER;
  private static final String FC_RESOURCE = "wt.fc.fcResource";
  private static final String RESOURCE = "ext.generic.wfaugment.processors.processorsResource";
  private static final String CLASSNAME = WfAugmentServiceFwd.class.getName();
  private static WTProperties wtproperties;
  private static Hashtable activity2Role = new Hashtable();

  static
  {
    wtproperties = null;
    try
    {
      SERVER = RemoteMethodServer.ServerFlag;
      wtproperties = WTProperties.getLocalProperties();
      VERBOSE = wtproperties.getProperty("ext.generic.wfaugment.verbose", true);
    }
    catch (Throwable t)
    {
      throw new ExceptionInInitializerError(t);
    }
  }

  private static Manager getManager()
    throws WTException
  {
    Manager manager = ManagerServiceFactory.getDefault().getManager(WfAugmentService.class);
    if (manager == null)
    {
      Object[] aobj = 
        { "ext.generic.wfaugment.processors.WfAugmentService" };
      throw new WTException("wt.fc.fcResource", "40", aobj);
    }

    return manager;
  }

  public String augmentRolesSelects(String oid)
    throws Exception
  {
    if (!SERVER)
    {
      try
      {
        Class[] aclass = 
          { String.class };
        Object[] aobj = 
          { oid };
        return (String)RemoteMethodServer.getDefault().invoke("augmentRolesSelects", CLASSNAME, null, aclass, aobj);
      }
      catch (InvocationTargetException invocationtargetexception)
      {
        Throwable throwable = invocationtargetexception.getTargetException();
        if ((throwable instanceof WTException))
        {
          throw ((WTException)throwable);
        }

        Object[] aobj2 = 
          { "augmentRolesSelects" };
        throw new WTException(throwable, "wt.fc.fcResource", "0", aobj2);
      }
      catch (RemoteException remoteexception)
      {
        Object[] aobj1 = 
          { "augmentRolesSelects" };
        throw new WTException(remoteexception, "wt.fc.fcResource", "0", aobj1);
      }
    }
    StringBuffer result = new StringBuffer();
    if (VERBOSE)
      System.out.println(">>>enter augmentRolesSelects...... oid = " + oid);
    ReferenceFactory referencefactory = new ReferenceFactory();
    WorkItem myWorkItem = (WorkItem)referencefactory.getReference(oid).getObject();
    if (VERBOSE)
      System.out.println(">>>enter augmentRolesSelects...... myWorkItem = " + myWorkItem);
    WfAssignedActivity activity = null;
    activity = (myWorkItem.getSource().getObject() instanceof WfAssignedActivity) ? (WfAssignedActivity)myWorkItem.getSource().getObject() : null;
    if (VERBOSE)
      System.out.println(">>>enter augmentRolesSelects...... activity = " + activity);
    String activityName = activity.getName();
    if (VERBOSE) {
      System.out.println("        &&&&DEBUG:      activityName = " + activityName);
    }
    String augmentRolesName = WfAugmentUtil.getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.roles.vector");
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      每一活动要为其指定参与者的角色名称 = " + augmentRolesName);
    String augmentRolesStr = (String)activity.getContext().getValue(augmentRolesName);
    if (VERBOSE) {
      System.out.println("        &&&&DEBUG:      augmentRolesStr = " + augmentRolesStr);
    }
    Vector augmentRoles = new Vector();
    augmentRoles = parseRoleStr(augmentRolesStr);
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      augmentRoles = " + augmentRoles.size());
    WfProcess wfprocess = activity.getParentProcess();
    activity2Role = getActivity2Role(wfprocess);
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      activity2Role = " + activity2Role);
    WTObject pbo = (WTObject)wfprocess.getContext().getValue("primaryBusinessObject");
    Team curTeam = (Team)wfprocess.getTeamId().getObject();
    System.out.println("curTeam:" + curTeam.getName());
    Locale locale = SessionHelper.manager.getLocale();
    ReferenceFactory rf = new ReferenceFactory();
    printJavaScript(augmentRoles, result, locale, pbo);

    result.append("<table>");
    result.append("<tr>");
    result.append("<td>");
    result.append("<table align=\"right\">");
    result.append("<tr><td>");
    result.append(WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "9", null, locale));
    result.append("</td></tr>");
    result.append("<tr><td>");
    result.append("<select name=\"ContainerRoles\" onChange=\"onSelectContainerRole(this)\" style=\"WIDTH: 230px\">");
    String Null = " ";
    result.append("<option value=\"" + Null + "\">" + Null + "</option>");
    for (int i = 0; i < augmentRoles.size(); i++)
    {
      String roleStr = (String)augmentRoles.elementAt(i);
      Role role = Role.toRole(roleStr);
      result.append("<option value=\"" + role.toString() + "\">" + role.getDisplay(locale) + "</option>");
    }
    result.append("</select>");
    result.append("</td></tr>");

    result.append("<tr><td>");
    result.append("<select name=\"Participants\" size=\"15\" style=\"WIDTH: 230px\">");
    result.append("<option value=\"" + Null + "\">" + Null + "</option>");
    result.append("</select>");
    result.append("</td></tr>");

    result.append("</table>");
    result.append("</td>");
    result.append("<td>");
    result.append("<table>");
    result.append("<tr><td>");

    result.append("<input name=\"addUsers\" type=\"button\" value=\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "6", null, locale) + "\" onClick=\"addDocParticipants(this)\">");

    result.append("</td></tr>");
    result.append("<tr><td>");

    result.append("<input name=\"findUsersBtn\" type=\"button\" disabled=\"true\" value=\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "8", null, locale) + "\" onClick=\"findUsers2()\">");

    result.append("</td></tr>");
    result.append("<tr><td>");

    result.append("<input name=\"removeUsers\" type=\"button\" value=\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "7", null, locale) + "\" onClick=\"removeDocParticipants(this)\">");

    result.append("</td></tr>");
    result.append("<tr><td><input type=\"hidden\" name=\"selectHidden\" value=\"\"/></td></tr>");
    result.append("</table>");
    result.append("</td>");
    result.append("<td>");
    result.append("<table>");
    result.append("<tr><td>");
    result.append(WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "10", null, locale));
    result.append("</td></tr>");
    result.append("<tr><td>");
    result.append("<select name=\"SelectedParticipants\" size=\"15\" style=\"WIDTH: 230px\">");
    for (int i = 0; i < augmentRoles.size(); i++)
    {
      String roleStr = (String)augmentRoles.elementAt(i);
      Role role = Role.toRole(roleStr);
      Enumeration participants = getRoleEnumeration(curTeam, role.toString());
      if (!participants.hasMoreElements())
        continue;
      result.append("<option value=\"" + role.toString() + "_separator" + "\">" + "---" + role.getDisplay(Locale.CHINA) + "---" + "</option>");
      while (participants.hasMoreElements())
      {
        WTPrincipal wtp = ((WTPrincipalReference)participants.nextElement()).getPrincipal();
        String id = getPrincipalIdentity(wtp);
        result.append("<option value=\"" + role.toString() + "_" + referencefactory.getReferenceString(wtp) + "\">" + id + "</option>");
      }
    }

    result.append("</select>");
    result.append("</td></tr>");
    result.append("</table>");
    result.append("</td>");
    result.append("</tr>");
    result.append("<tr><td align=right>");
    result.append("</td></tr>");
    result.append("<input type=hidden name=\"RolesParticipants\" value=\"\">");
    result.append("</table>");
    if (VERBOSE)
      System.out.println("<<<out augmentRolesSelects.");
    return result.toString();
  }

  private void printJavaScript(Vector containerRoles, StringBuffer result, Locale locale, WTObject pbo)
    throws WTException, IOException
  {
    ReferenceFactory rf = new ReferenceFactory();
    result.append("<script language=\"javascript\" type=\"text/javascript\">");

    result.append("function HashMap()");
    result.append("{");
    result.append("         var size = 0;");
    result.append("         var entry = new Object();");

    result.append("     this.put = function (key , value)");
    result.append("     {");
    result.append("         if(!this.containsKey(key))");
    result.append("         {");
    result.append("             size ++ ;");
    result.append("         }");
    result.append("         entry[key] = value;");
    result.append("     };");

    result.append("     this.get = function (key)");
    result.append("     {");
    result.append("         return this.containsKey(key) ? entry[key] : null;");
    result.append("     };");

    result.append("     this.remove = function ( key )");
    result.append("     {");
    result.append("         if( this.containsKey(key) && ( delete entry[key] ) )");
    result.append("         {");
    result.append("             size --;");
    result.append("         }");
    result.append("     };");

    result.append("     this.containsKey = function ( key )");
    result.append("     {");
    result.append("         return (key in entry);");
    result.append("     };");

    result.append("     this.containsValue = function ( value )");
    result.append("     {");
    result.append("         for(var prop in entry)");
    result.append("         {");
    result.append("             if(entry[prop] == value)");
    result.append("             {");
    result.append("                 return true;");
    result.append("             }");
    result.append("         }");
    result.append("         return false;");
    result.append("     };");

    result.append("     this.values = function ()");
    result.append("     {");
    result.append("         var values = new Array();");
    result.append("         for(var prop in entry)");
    result.append("         {");
    result.append("             values.push(entry[prop]);");
    result.append("         }");
    result.append("         return values;");
    result.append("     };");

    result.append("     this.keys = function ()");
    result.append("     {");
    result.append("         var keys = new Array();");
    result.append("         for(var prop in entry)");
    result.append("         {");
    result.append("             keys.push(prop);");
    result.append("         }");
    result.append("         return keys;");
    result.append("     };");

    result.append("     this.size = function ()");
    result.append("     {");
    result.append("         return size;");
    result.append("     };");

    result.append("     this.clear = function ()");
    result.append("     {");
    result.append("         size = 0;");
    result.append("         entry = new Object();");
    result.append("     };");
    result.append(" }");

    result.append("function onSelectContainerRole(button)");
    result.append("{");
    result.append("    var thisForm=  button.form;");
    result.append("    var participantSelect=thisForm.Participants;");
    result.append("    var selectedItem = thisForm.ContainerRoles.selectedIndex;");
    result.append("    var containerRole = thisForm.ContainerRoles.options[selectedItem].value;");
    result.append("    clearSelect(participantSelect);");
    result.append("    thisForm.findUsersBtn.disabled=true;");
    result.append("    var map = new HashMap();");
    Hashtable ht = new Hashtable();
    if ((pbo instanceof WTDocument))
      ht = getRolesParticipant((WTDocument)pbo);
    if ((pbo instanceof WTPart))
      ht = getRolesParticipant((WTPart)pbo);
    if ((pbo instanceof EPMDocument))
      ht = getRolesParticipant((EPMDocument)pbo);
    if ((pbo instanceof WTChangeRequest2))
      ht = getRolesParticipant((WTChangeRequest2)pbo);
    if ((pbo instanceof WTChangeOrder2))
      ht = getRolesParticipant((WTChangeOrder2)pbo);
    if ((pbo instanceof WTChangeActivity2))
      ht = getRolesParticipant((WTChangeActivity2)pbo);
    if ((pbo instanceof WTChangeIssue))
      ht = getRolesParticipant((WTChangeIssue)pbo);
    if ((pbo instanceof PromotionNotice))
      ht = getRolesParticipant((PromotionNotice)pbo);
    if ((pbo instanceof ManagedBaseline))
      ht = getRolesParticipant((ManagedBaseline)pbo);
    if (VERBOSE)
      System.out.println("        &&&&DEBUG: containerRoles..." + containerRoles.size());
    for (int i = 0; i < containerRoles.size(); i++)
    {
      String roleStr = (String)containerRoles.elementAt(i);
      if (VERBOSE)
        System.out.println("    &&&&DEBUG: roleStr..." + roleStr);
      Role role = Role.toRole(roleStr);
      Vector participants = parseRoleParticipants(role.toString(), pbo, ht);

      HashMap temhm = new HashMap();
      String[] arr = new String[participants.size()];
      Comparator cmp = Collator.getInstance(Locale.CHINA);
      for (int j = 0; j < participants.size(); j++) {
        WTPrincipal principal = (WTPrincipal)participants.elementAt(j);
        String key = role.toString() + "_" + rf.getReferenceString(principal);
        String identity = getPrincipalIdentity(principal);
        temhm.put(key, identity);
      }
      Iterator iter = temhm.entrySet().iterator();
      int temi = 0;
      while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry)iter.next();
        Object key = entry.getKey();
        Object val = entry.getValue();
        arr[temi] = (val.toString() + "&" + key.toString());
        temi++;
      }
      Arrays.sort(arr, cmp);
      String[] arrT = null;
      for (int ii = 0; ii < arr.length; ii++) {
        arrT = arr[ii].split("&");
        result.append("map.put (\"" + arrT[1] + "\", \"" + arrT[0] + "\");");
      }

    }

    result.append("    var kkk = map.keys();");
    result.append("    var flag=false;");
    result.append("    for (i=0; i<map.size(); i++)");
    result.append("    {");
    result.append("        var kk= kkk[i];");
    result.append("        if(kk.indexOf(containerRole + '_')==0)");
    result.append("        {");
    result.append("            var display= map.get(kk);");
    result.append("                 var value= kk.substring(kk.indexOf('_') + 1);");
    result.append("                 addOption(participantSelect, display, kk);");
    result.append("                         flag=true;");
    result.append("        }");
    result.append("    }");

    result.append("       if(!flag)");
    result.append("       thisForm.findUsersBtn.disabled=false;");
    result.append("}");
    result.append("function addDocParticipants(button)");
    result.append("{");
    result.append("         var debug=false;");
    result.append("         var thisForm = button.form;");
    result.append("         if (thisForm.Participants.length == 0)");
    result.append("         {");
    result.append("                 window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "1", null, locale) + "\");");
    result.append("                 return;");
    result.append("         }");
    result.append("         if (thisForm.Participants.selectedIndex < 0)");
    result.append("         {");
    result.append("                 window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "2", null, locale) + "\");");
    result.append("                 return;");
    result.append("         }");
    result.append("         var count = thisForm.SelectedParticipants.length;");
    result.append("         var selectedItem = thisForm.Participants.selectedIndex;");
    result.append("         var selectedValue = thisForm.Participants.options[selectedItem].value;");
    result.append("         var role = selectedValue.substring(0,selectedValue.lastIndexOf(\"_\"));");
    result.append("         var selectedDisplay= thisForm.Participants.options[selectedItem].text;");

    result.append("         var selectedItem1 = thisForm.ContainerRoles.selectedIndex;");
    result.append("         var selectedDisplay1= \"---\" + thisForm.ContainerRoles.options[selectedItem1].text + \"---\";");
    result.append("         if(debug) alert(\"role= \"+ role + \"; display=\" + selectedDisplay);");
    result.append("         var roleSeparator= role + \"_separator\";");
    result.append("         var i; var isNew = true; var isNew1 = true; var index=0;");
    result.append("         if (count != 0)");
    result.append("         {");
    result.append("                 for (i = 0; i < count; i++)");
    result.append("                 {");
    result.append("                         thisitem = thisForm.SelectedParticipants.options[i].value;");
    result.append("                         if (thisitem == selectedValue)");
    result.append("                         {");
    result.append("                                 isNew = false;");
    result.append("                 window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "3", null, locale) + "\");");
    result.append("                                 break;");
    result.append("                         }");
    result.append("                 }");
    result.append("         }");
    result.append("         if (isNew)");
    result.append("         {");
    result.append("                 if (count != 0)");
    result.append("                 {");
    result.append("                         for (i = 0; i < count; i++)");
    result.append("                         {");
    result.append("                                 thisitem = thisForm.SelectedParticipants.options[i].text;");
    result.append("                                 if (thisitem == selectedDisplay1)");
    result.append("                                 {");
    result.append("                                         insertOption(thisForm.SelectedParticipants, selectedDisplay, selectedValue,i);");
    result.append("                                         isNew1 = false;");
    result.append("                                         break;");
    result.append("                                 }");
    result.append("                         }");
    result.append("                 }");
    result.append("                 if (isNew1)");
    result.append("                 {");
    result.append("                         insertOption(thisForm.SelectedParticipants, selectedDisplay1, roleSeparator,count);");
    result.append("                         insertOption(thisForm.SelectedParticipants, selectedDisplay, selectedValue,count+1);");
    result.append("                 }");
    result.append("                 if(debug) alert(\" insert one participant!\");");
    result.append("         }");
    result.append("         thisForm.Participants.selectedIndex = -1;");
    result.append("}");

    result.append("function removeDocParticipants(button)");
    result.append("{");
    result.append("         var thisForm = button.form;");
    result.append("         var count = thisForm.SelectedParticipants.length;");
    result.append("         if (count == 0)");
    result.append("         {");
    result.append("                 window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "4", null, locale) + "\");");
    result.append("                 return;");
    result.append("         }");
    result.append("         var selectedItem = thisForm.SelectedParticipants.selectedIndex;");
    result.append("         if (selectedItem >= 0)");
    result.append("         {");
    result.append("                 var thisitem = thisForm.SelectedParticipants.options[selectedItem].value;");
    result.append("                 if(thisitem.indexOf(\"_separator\")>0)");
    result.append("                 {");
    result.append("                         window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "5", null, locale) + "\");");
    result.append("                         return;");
    result.append("                 }");
    result.append("                 else");
    result.append("                 {");
    result.append("                         var thisValue = thisForm.SelectedParticipants.options[selectedItem].value;");
    result.append("                         var selectedItem1 = selectedItem - 1;");
    result.append("                         var begin = thisValue.substring(0,thisValue.lastIndexOf(\"_\"));");
    result.append("                         var j = 0;");
    result.append("                         thisForm.SelectedParticipants.options[selectedItem] = null;");
    result.append("                         for (i = 0; i < thisForm.SelectedParticipants.length; i++)");
    result.append("                         {");
    result.append("                                 var thisItem = thisForm.SelectedParticipants.options[i].value;");
    result.append("                                 var thisBegin = thisItem.substring(0,thisItem.lastIndexOf(\"_\"));");
    result.append("                                 if(thisBegin == begin) j = j + 1;");
    result.append("                         }");
    result.append("                         if(j == 1)");
    result.append("                                 thisForm.SelectedParticipants.options[selectedItem1] = null;");
    result.append("                 }");
    result.append("         }");
    result.append("         else");
    result.append("         {");
    result.append("                 window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "5", null, locale) + "\");");
    result.append("         }");
    result.append("}");

    result.append("function addDocParticipants1(user,selectedDisplay)");
    result.append("{");
    result.append("         var thisForm = document.forms[0];");
    result.append("         var count = thisForm.SelectedParticipants.length;");
    result.append("         var selectedItem = thisForm.ContainerRoles.selectedIndex;");
    result.append("         var selectedValue = thisForm.ContainerRoles.options[selectedItem].value+\"_\"+user;");
    result.append("         var role = thisForm.ContainerRoles.options[selectedItem].value;");
    result.append("         var selectedDisplay1= \"---\" + thisForm.ContainerRoles.options[selectedItem].text + \"---\";");
    result.append("         var roleSeparator= role + \"_separator\";");
    result.append("         var i; var isNew = true; var isNew1 = true; var index=0;");
    result.append("         if (count != 0)");
    result.append("         {");
    result.append("                 for (i = 0; i < count; i++)");
    result.append("                 {");
    result.append("                         thisitem = thisForm.SelectedParticipants.options[i].value;");
    result.append("                         if (thisitem == selectedValue)");
    result.append("                         {");
    result.append("                                 isNew = false; ");
    result.append("                                 window.alert(\"" + WTMessage.getLocalizedMessage("ext.generic.wfaugment.processors.processorsResource", "3", null, locale) + "\");");
    result.append("                                 break;");
    result.append("                         }");
    result.append("                 }");
    result.append("         }");
    result.append("         if (isNew)");
    result.append("         {");
    result.append("                 if (count != 0)");
    result.append("                 {");
    result.append("                         for (i = 0; i < count; i++)");
    result.append("                         {");
    result.append("                                 thisitem = thisForm.SelectedParticipants.options[i].text;");
    result.append("                                 if (thisitem == selectedDisplay1)");
    result.append("                                 {");
    result.append("                                         insertOption(thisForm.SelectedParticipants, selectedDisplay, selectedValue,i);");
    result.append("                                         isNew1 = false;");
    result.append("                                         break;");
    result.append("                                 }");
    result.append("                         }");
    result.append("                 }");
    result.append("                 if (isNew1)");
    result.append("                 {");
    result.append("                         insertOption(thisForm.SelectedParticipants, selectedDisplay1, roleSeparator,count);");
    result.append("                         insertOption(thisForm.SelectedParticipants, selectedDisplay, selectedValue,count+1);");
    result.append("                 }");
    result.append("         }");
    result.append("         thisForm.Participants.selectedIndex = -1;");
    result.append("}");

    result.append("function findUsers2()");
    result.append("{");
    result.append("var pathname = window.location.pathname;");
    result.append("var splitPathname = pathname.split('/');");
    result.append("var wcHome = window.location.protocol + '//' + window.location.host + '/' + splitPathname[1] + '/';");
    result.append("var jspName = 'netmarkets/jsp/ext/generic/part/addParticipantsBySearch.jsp';");
    result.append("var fullURL = wcHome + jspName;");
    result.append("window.open(fullURL,'find_users', 'resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,status=yes,top=50,left=100,height=400,width=500');");

    result.append("}");
    result.append("function setChildData(message){");

    result.append("if(message && message.length>0 && message!=' '){");
    result.append("message=message.split('&');");
    result.append("for(var i=0;i<message.length;i++)");
    result.append("{");
    result.append("var str=message[i];");
    result.append("var str1=str.split(';');");
    result.append("addDocParticipants1(str1[0],str1[1]);");
    result.append("}");
    result.append("}");
    result.append("}");

    result.append("</script>");
  }

  private Hashtable getRolesParticipant(WTDocument doc)
    throws IOException, WTException
  {
    if (VERBOSE)
      System.out.println(">>>" + CLASSNAME + ".getRolesParticipant(WTDocument)--pbo=" + doc.getDisplayIdentity());
    Hashtable ht = new Hashtable();

    String docType = WfAugmentUtil.getDocType(doc);
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      docType = " + docType);
    Hashtable ibaValues = IBAUtil.getIBAValues(doc);
    String docAttribute = "";
    String smallType = WfAugmentUtil.getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.doc.smallType");
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      文档小类软属性名称 = " + smallType);
    if ((smallType != null) && (smallType.length() > 0))
      docAttribute = (String)ibaValues.get(smallType);
    if (VERBOSE)
      System.out.println("    &&&&DEBUG:  docAttribute = " + docAttribute);
    if (docAttribute == null)
      docAttribute = "";
    if (VERBOSE) {
      System.out.println("        final doc detail type=" + docAttribute);
    }
    String configFilePath = WfAugmentUtil.getConfigFilePath(doc);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;

    int nAttributeRow = 0;
    for (int i = 1; i <= nSheetRow; i++)
    {
      String s = getExcelCellContent(sheet, i, 0);
      if ((docType.length() != 0) && (s.equalsIgnoreCase(docType)))
      {
        if (docAttribute.length() == 0)
        {
          nAttributeRow = i;
          break;
        }

        for (int j = i + 1; j < nSheetRow; j++)
        {
          String ss = getExcelCellContent(sheet, j, 1);

          if ((ss == null) || (ss.length() == 0))
            break;
          if ((docAttribute.length() == 0) || (!ss.equalsIgnoreCase(docAttribute)))
            continue;
          nAttributeRow = j;
          break;
        }

      }

      if (nAttributeRow != 0)
        break;
    }
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      nAttributeRow = " + nAttributeRow);
    if (nAttributeRow == 0)
    {
      if (VERBOSE) {
        System.out.println("    签审指南里没有定义此小类：" + docAttribute);
      }
    }
    else
    {
      XSSFRow row = sheet.getRow(nAttributeRow);
      nSheetCol = row.getLastCellNum();
      for (int i = 2; i < nSheetCol; i++)
      {
        String temp = getExcelCellContent(sheet, nAttributeRow, i);
        if ((temp == null) || (temp.length() <= 0))
          continue;
        String temp1 = getExcelCellContent(sheet, 0, i);
        String temp2 = (String)activity2Role.get(temp1);
        if ((temp2 == null) || (temp2.length() == 0))
          continue;
        temp2 = activity2Role.get(temp1).toString();
        if (VERBOSE)
        {
          System.out.println("        签审指南定义: " + temp1 + "=" + temp);
        }
        if ((temp2 != null) && (temp2.length() != 0))
          System.out.println("key:" + temp2 + "------> value: " + temp);
        ht.put(temp2, temp);
      }

    }

    if (VERBOSE) {
      System.out.println("<<<" + CLASSNAME + ".getRolesParticipant(WTDocument).");
    }
    return ht;
  }

  private Hashtable getRolesParticipant(WTPart part)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    boolean noSmallType = false;
    String smallType = WfAugmentUtil.getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.part.smallType");
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      零部件类型软属性名称 = " + smallType);
    if ((smallType == null) || (smallType.length() == 0))
    {
      if (VERBOSE)
        System.out.println("    &&&&DEBUG:      系统未定义零部件类型软属性，直接读取签审指南的第二行。。。");
      noSmallType = true;
    }
    String partAttribute = "";
    if (!noSmallType)
    {
      partAttribute = (String)IBAUtil.getIBAValue(part, smallType);
      partAttribute = partAttribute != null ? partAttribute : "";
    }

    String configFilePath = WfAugmentUtil.getConfigFilePath(part);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    XSSFRow row0 = sheet.getRow(0);
    int nSheetCol = row0.getLastCellNum();
    if (noSmallType)
    {
      for (int j = 1; j < nSheetCol; j++)
      {
        String temp = getExcelCellContent(sheet, 1, j);
        if ((temp == null) || (temp.length() <= 0))
          continue;
        String temp1 = getExcelCellContent(sheet, 0, j);
        System.out.println("    excel cell=" + temp1);
        String temp2 = (String)activity2Role.get(temp1);
        if ((temp2 != null) && (temp2.length() > 0)) {
          ht.put(temp2, temp);
        }
      }
    }
    else
    {
      for (int i = 1; i < nSheetRow; i++)
      {
        String s = getExcelCellContent(sheet, i, 0);
        if ((partAttribute.length() == 0) || (!s.equalsIgnoreCase(partAttribute)))
          continue;
        for (int j = 1; j < nSheetCol; j++)
        {
          String temp = getExcelCellContent(sheet, i, j);
          if ((temp == null) || (temp.length() <= 0))
            continue;
          String temp1 = getExcelCellContent(sheet, 0, j);
          System.out.println("    excel cell=" + temp1);
          String temp2 = (String)activity2Role.get(temp1);
          if ((temp2 != null) && (temp2.length() > 0)) {
            ht.put(temp2, temp);
          }
        }
      }

    }

    return ht;
  }

  private Hashtable getRolesParticipant(EPMDocument doc)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    String configFilePath = WfAugmentUtil.getConfigFilePath(doc);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    int nAttributeRow = 1;
    XSSFRow row = sheet.getRow(nAttributeRow);
    nSheetCol = row.getLastCellNum();
    for (int i = 1; i < nSheetCol; i++)
    {
      String temp = getExcelCellContent(sheet, nAttributeRow, i);

      if ((temp == null) || (temp.length() <= 0))
        continue;
      String temp1 = getExcelCellContent(sheet, 0, i);
      String temp2 = activity2Role.get(temp1).toString();
      ht.put(temp2, temp);
    }

    return ht;
  }

  private Hashtable getRolesParticipant(WTChangeOrder2 ecn)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    boolean noBigType = false;
    String bigType = "";
    bigType = WfAugmentUtil.getECNType(ecn);
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      变更通告类型 = " + bigType);
    if ((bigType == null) || (bigType.length() == 0))
    {
      if (VERBOSE)
        System.out.println("    &&&&DEBUG:      变更通告大类为空！");
      noBigType = true;
    }

    String configFilePath = WfAugmentUtil.getConfigFilePath(ecn);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    if (noBigType)
    {
      XSSFRow row = sheet.getRow(1);
      nSheetCol = row.getLastCellNum();
      for (int j = 1; j < nSheetCol; j++)
      {
        String temp = getExcelCellContent(sheet, 1, j);
        if ((temp == null) || (temp.length() <= 0))
          continue;
        String temp1 = getExcelCellContent(sheet, 0, j);
        String temp2 = activity2Role.get(temp1).toString();
        ht.put(temp2, temp);
      }

    }
    else
    {
      for (int i = 1; i < nSheetRow; i++)
      {
        String s = getExcelCellContent(sheet, i, 0);
        if ((bigType.length() == 0) || (!s.equalsIgnoreCase(bigType))) {
          continue;
        }
        XSSFRow row = sheet.getRow(i);
        nSheetCol = row.getLastCellNum();
        for (int j = 1; j < nSheetCol; j++)
        {
          String temp = getExcelCellContent(sheet, i, j);
          if ((temp == null) || (temp.length() <= 0))
            continue;
          String temp1 = getExcelCellContent(sheet, 0, j);

          if (VERBOSE) {
            System.out.println("    &&&&DEBUG:      temp1=" + temp1);
          }

          String temp2 = activity2Role.get(temp1).toString();
          ht.put(temp2, temp);
        }
      }

    }

    return ht;
  }

  private Hashtable getRolesParticipant(WTChangeRequest2 ecr)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    boolean noSmallType = false;
    String smallType = WfAugmentUtil.getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.ecr.smallType");
    if ((smallType == null) || (smallType.length() == 0))
    {
      if (VERBOSE)
        System.out.println("    &&&&DEBUG:      系统未定义变更请求变更类型软属性，直接读取签审指南的第二行。。。");
      noSmallType = true;
    }
    String attribute = "";
    if (!noSmallType)
    {
      attribute = (String)IBAUtil.getIBAValue(ecr, smallType);
      attribute = attribute != null ? attribute : "";
    }

    String configFilePath = WfAugmentUtil.getConfigFilePath(ecr);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    int nAttributeRow = 1;
    XSSFRow row = sheet.getRow(nAttributeRow);
    nSheetCol = row.getLastCellNum();
    if (noSmallType) {
      for (int j = 1; j < nSheetCol; j++)
      {
        String temp = getExcelCellContent(sheet, 1, j);
        if ((temp == null) || (temp.length() <= 0))
          continue;
        String temp1 = getExcelCellContent(sheet, 0, j);
        String temp2 = activity2Role.get(temp1).toString();
        ht.put(temp2, temp);
      }
    }
    else {
      for (int i = 1; i < nSheetRow; i++)
      {
        String s = getExcelCellContent(sheet, i, 0);
        if ((attribute.length() == 0) || (!s.equalsIgnoreCase(attribute)))
          continue;
        for (int j = 1; j < nSheetCol; j++)
        {
          String temp = getExcelCellContent(sheet, i, j);
          if ((temp == null) || (temp.length() <= 0))
            continue;
          String temp1 = getExcelCellContent(sheet, 0, j);
          String temp2 = activity2Role.get(temp1).toString();
          ht.put(temp2, temp);
        }
      }
    }

    return ht;
  }

  private Hashtable getRolesParticipant(WTChangeActivity2 eca)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    String configFilePath = WfAugmentUtil.getConfigFilePath(eca);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    int nAttributeRow = 1;
    XSSFRow row = sheet.getRow(nAttributeRow);
    nSheetCol = row.getLastCellNum();
    for (int i = 1; i < nSheetCol; i++)
    {
      String temp = getExcelCellContent(sheet, nAttributeRow, i);
      if (VERBOSE) {
        System.out.println("    &&&&DEBUG:      ");
      }
      if ((temp == null) || (temp.length() <= 0))
        continue;
      String temp1 = getExcelCellContent(sheet, 0, i);
      if (VERBOSE)
        System.out.println("        &&&&DEBUG:      tem1=" + temp1);
      String temp2 = activity2Role.get(temp1).toString();
      ht.put(temp2, temp);
    }

    return ht;
  }

  private Hashtable getRolesParticipant(WTChangeIssue pr)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    String configFilePath = WfAugmentUtil.getConfigFilePath(pr);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    int nAttributeRow = 1;
    XSSFRow row = sheet.getRow(nAttributeRow);
    nSheetCol = row.getLastCellNum();
    for (int i = 1; i < nSheetCol; i++)
    {
      String temp = getExcelCellContent(sheet, nAttributeRow, i);
      if (VERBOSE) {
        System.out.println("    &&&&DEBUG:      ");
      }
      if ((temp == null) || (temp.length() <= 0))
        continue;
      String temp1 = getExcelCellContent(sheet, 0, i);
      if (VERBOSE)
        System.out.println("        &&&&DEBUG:      tem1=" + temp1);
      String temp2 = activity2Role.get(temp1).toString();
      if (VERBOSE)
        System.out.println("        &&&&DEBUG:      tem2=" + temp2);
      ht.put(temp2, temp);
    }

    return ht;
  }

  public Hashtable getRolesParticipant(ManagedBaseline bs)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    String configFilePath = WfAugmentUtil.getConfigFilePath(bs);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    int nAttributeRow = 1;
    XSSFRow row = sheet.getRow(nAttributeRow);
    nSheetCol = row.getLastCellNum();
    for (int i = 1; i <= nSheetCol; i++)
    {
      String temp = getExcelCellContent(sheet, nAttributeRow, i);
      if ((temp == null) || (temp.length() <= 0))
        continue;
      System.out.println("\t i=" + i);
      String temp1 = getExcelCellContent(sheet, 0, i);
      if (!activity2Role.containsKey(temp1))
        continue;
      String temp2 = activity2Role.get(temp1).toString();
      if (VERBOSE)
      {
        System.out.println("\t 活动名称 = " + temp1);
        System.out.println("\t 活动对应角色 = " + temp2);
        System.out.println("\t 读取到的签审指南内容 = " + temp);
      }
      ht.put(temp2, temp);
    }

    return ht;
  }

  public Hashtable getRolesParticipant(PromotionNotice br)
    throws IOException, WTException
  {
    Hashtable ht = new Hashtable();
    String configFilePath = WfAugmentUtil.getConfigFilePath(br);
    File configFile = new File(configFilePath);
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(configFile));
    XSSFSheet sheet = workbook.getSheetAt(0);
    int nSheetRow = sheet.getLastRowNum();
    int nSheetCol = 0;
    int nAttributeRow = 1;
    XSSFRow row = sheet.getRow(nAttributeRow);
    nSheetCol = row.getLastCellNum();
    for (int i = 1; i < nSheetCol; i++)
    {
      String temp = getExcelCellContent(sheet, nAttributeRow, i);
      if ((temp == null) || (temp.length() <= 0))
        continue;
      System.out.println("\t i=" + i);
      String temp1 = getExcelCellContent(sheet, 0, i);
      if (!activity2Role.containsKey(temp1))
        continue;
      String temp2 = activity2Role.get(temp1).toString();
      if (VERBOSE)
      {
        System.out.println("\t 活动名称 = " + temp1);
        System.out.println("\t 活动对应角色 = " + temp2);
        System.out.println("\t 读取到的签审指南内容 = " + temp);
      }
      ht.put(temp2, temp);
    }

    return ht;
  }

  public void save(NmCommandBean nmcommandbean, String participants)
    throws WTException
  {
    if (!SERVER)
    {
      try
      {
        Class[] aclass = 
          { NmCommandBean.class, String.class };
        Object[] aobj = 
          { nmcommandbean, participants };
        RemoteMethodServer.getDefault().invoke("save", CLASSNAME, null, aclass, aobj);
        return;
      }
      catch (InvocationTargetException invocationtargetexception)
      {
        Throwable throwable = invocationtargetexception.getTargetException();
        if ((throwable instanceof WTException))
        {
          throw ((WTException)throwable);
        }

        Object[] aobj2 = 
          { "save" };
        throw new WTException(throwable, "wt.fc.fcResource", "0", aobj2);
      }
      catch (RemoteException remoteexception)
      {
        Object[] aobj1 = 
          { "save" };
        throw new WTException(remoteexception, "wt.fc.fcResource", "0", aobj1);
      }

    }

    if (VERBOSE)
      System.out.println("=> WfAugmentServiceFwd.save ");
    NmOid nmoid = nmcommandbean.getPageOid();
    if (VERBOSE)
      System.out.println("=> WfAugmentServiceFwd.save nmoid = " + nmoid);
    WorkItem workitem = (WorkItem)nmoid.getRef();
    if (VERBOSE)
      System.out.println("=> WfAugmentServiceFwd.save workitem = " + workitem);
    boolean flag = SessionServerHelper.manager.isAccessEnforced();

    SessionServerHelper.manager.setAccessEnforced(false);
    WfActivity wfactivity = (WfActivity)workitem.getSource().getObject();
    if (VERBOSE)
      System.out.println("=> WfAugmentServiceFwd.save wfactivity = " + wfactivity);
    PersistenceHelper.manager.save(wfactivity);
    WfProcess wfProcess = wfactivity.getParentProcess();
    if (VERBOSE)
      System.out.println("=> WfAugmentServiceFwd.save wfProcess = " + wfProcess);
    PersistenceHelper.manager.save(wfProcess);
    Team team = (Team)wfProcess.getTeamId().getObject();
    String augmentRolesName = WfAugmentUtil.getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.roles.vector");
    if (VERBOSE)
      System.out.println("    &&&&DEBUG:      每一活动要为其指定参与者的角色Vector名称 = " + augmentRolesName);
    String augmentRolesStr = (String)wfactivity.getContext().getValue(augmentRolesName);
    if (VERBOSE) {
      System.out.println("        &&&&DEBUG:      augmentRolesStr = " + augmentRolesStr);
    }
    Vector augmentRoles = new Vector();
    augmentRoles = parseRoleStr(augmentRolesStr);
    for (int i = 0; i < augmentRoles.size(); i++)
    {
      String roleStr = (String)augmentRoles.elementAt(i);
      Role role = Role.toRole(roleStr);
      team = clearTeamRole(team, role.toString());
      team = (Team)PersistenceHelper.manager.refresh(team);
    }

    if ((participants != null) && (participants.length() > 0))
    {
      System.out.println("参与者的信息为：" + participants);
      if (VERBOSE)
        System.out.println("        &&&&DEBUG: begin save RolesParticipants...");
      StringTokenizer strTk = new StringTokenizer(participants, ";");
      ReferenceFactory referencefactory = new ReferenceFactory();
      while (strTk.hasMoreTokens())
      {
        String token = strTk.nextToken();
        String roleString = token.substring(0, token.lastIndexOf("_"));
        String userOid = token.substring(token.lastIndexOf("_") + 1);
        WTPrincipal principal = (WTPrincipal)referencefactory.getReference(userOid).getObject();
        WTPrincipalReference principalRef = WTPrincipalReference.newWTPrincipalReference(principal);
        Vector vectors = new Vector();
        vectors.addElement(principalRef);
        team = (Team)WorkflowUtil.addRolePrincipals(team, roleString, vectors.elements());
        team = (Team)PersistenceHelper.manager.refresh(team);
      }
    }
    SessionServerHelper.manager.setAccessEnforced(flag);
  }

  private static Team clearTeamRole(Team team, String rolename)
    throws WTException
  {
    Enumeration enums = getRoleEnumeration(team, rolename);
    while ((enums != null) && (enums.hasMoreElements()))
    {
      WTPrincipal wtp = ((WTPrincipalReference)enums.nextElement()).getPrincipal();
      boolean bool = deleteProcessRoleHolder(team, rolename, wtp);
    }
    return team;
  }

  private static Enumeration getRoleEnumeration(Team team, String rolename)
    throws WTException
  {
    if ((rolename == null) || (rolename.length() == 0))
      return null;
    Role role = Role.toRole(rolename);
    return team.getPrincipalTarget(role);
  }

  private static boolean deleteProcessRoleHolder(Team team, String rolename, WTPrincipal prin)
  {
    boolean flag = true;
    try
    {
      Role role = Role.toRole(rolename);
      team.deletePrincipalTarget(role, prin);
    }
    catch (Exception e)
    {
      System.out.println("        deleteProcessRoleHolder : error");
      e.printStackTrace();
      flag = false;
    }
    return flag;
  }

  private Hashtable getActivity2Role(WfProcess wfprocess)
    throws WTException
  {
    Hashtable ht = new Hashtable();
    WfProcessTemplate wfprocesstemplate = (WfProcessTemplate)wfprocess.getTemplate().getObject();
    for (QueryResult queryresult = PersistenceHelper.manager.navigate(wfprocesstemplate, "step", ProcessStepTemplateLink.class); queryresult.hasMoreElements(); )
    {
      Object obj = queryresult.nextElement();
      if (!(obj instanceof WfAssignedActivityTemplate))
        continue;
      WfAssignedActivityTemplate wfassignedactivitytemplate = (WfAssignedActivityTemplate)obj;
      Enumeration enums = wfassignedactivitytemplate.getRoles();
      while (enums.hasMoreElements())
      {
        String roleString = enums.nextElement().toString();
        if (roleString.equals("SUBMITTER"))
          continue;
        System.out.println("key:" + wfassignedactivitytemplate.getName() + "---------->  value:" + roleString);
        ht.put(wfassignedactivitytemplate.getName(), roleString);
        break;
      }

    }

    return ht;
  }

  private String getPrincipalIdentity(WTPrincipal principal)
  {
    String identity = "";
    if ((principal instanceof WTUser))
    {
      WTUser user = (WTUser)principal;
      identity = user.getFullName() + "(" + user.getName() + ")";
    }
    else
    {
      identity = principal.getName();
    }
    return identity;
  }

  public static String getExcelCellContent(XSSFSheet sheet, int nRow, int nCol)
  {
    if ((sheet == null) || (nRow < 0) || (nCol < 0))
      return "";
    try
    {
      XSSFRow row = sheet.getRow(nRow);
      if (row == null)
        return "";
      XSSFCell aCell = row.getCell(nCol);
      if (aCell == null)
        return "";
      String content = aCell.getStringCellValue();
      if (content != null)
        content = content.trim();
      if (content == null)
        content = "";
      return content;
    }
    catch (Exception e)
    {
      System.out.println("    getExcelCellContent : error, nRow = '" + nRow + "' , nCol = '" + nCol + "'");
      e.printStackTrace();
    }
    return "";
  }

  private Vector parseRoleParticipants(String roleName, Persistable pbo, Hashtable ht)
    throws IOException, WTException
  {
    if (VERBOSE) {
      System.out.println(">>>enter parseRoleParticipants......");
    }
    Vector participants = new Vector();
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      roleName = " + roleName);
    Object role = ht.get(roleName);
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      role = " + role);
    String roleString = "";
    if (role != null)
    {
      roleString = role.toString();
      if (VERBOSE)
        System.out.println("    &&&&DEBUG:      roleString = " + roleString);
      if (roleString.length() > 0)
        roleString = roleString.substring(1);
      roleString = roleString.trim();
      if (VERBOSE)
        System.out.println("    &&&&DEBUG:      roleString 2 = " + roleString);
      if (roleString.length() > 0)
      {
        StringTokenizer token = new StringTokenizer(roleString, "|");
        while (token.hasMoreElements())
        {
          String temp1 = token.nextToken();
          temp1 = temp1.trim();
          if (VERBOSE)
            System.out.println("    &&&&DEBUG:      temp1 = " + temp1);
          if (temp1.startsWith("R"))
            addRoleUser(pbo, participants, temp1);
          if (temp1.startsWith("G"))
            addGroupUser(participants, temp1);
        }
      }
    }
    if (VERBOSE) {
      System.out.println("<<<out parseRoleParticipants.");
    }
    return participants;
  }

  private void addRoleUser(Persistable pbo, Vector participants, String roleSet)
    throws WTException
  {
    if (VERBOSE) {
      System.out.println(">>>enter addRoleUser......");
    }
    if (roleSet.length() > 2)
    {
      roleSet = roleSet.substring(2);
      roleSet = roleSet.trim();

      if (VERBOSE)
        System.out.println("    &&&&DEBUG:      roleSet = " + roleSet);
      StringTokenizer token = new StringTokenizer(roleSet, ",");
      while (token.hasMoreElements())
      {
        String temp1 = token.nextToken();
        temp1 = temp1.trim();
        if (VERBOSE)
          System.out.println("        &&&&DEBUG:      temp1 = " + temp1);
        addRoleUser1(pbo, participants, temp1);
      }
    }
    if (VERBOSE)
      System.out.println("<<<out addRoleUser.");
  }

  private void addGroupUser(Vector participants, String groupSet)
    throws QueryException, WTException
  {
    if (groupSet.length() > 2)
    {
      groupSet = groupSet.substring(2);
      groupSet = groupSet.trim();

      StringTokenizer token = new StringTokenizer(groupSet, ",");
      while (token.hasMoreElements())
      {
        String temp1 = token.nextToken();
        temp1 = temp1.trim();
        addGroupUser1(participants, temp1);
      }
    }
  }

  private void addRoleUser1(Persistable pbo, Vector participants1, String roleName)
    throws WTException
  {
    if (VERBOSE) {
      System.out.println(">>>" + CLASSNAME + ".addRoleUser1()---role name=" + roleName);
    }
    WTContainer container = ((WTContained)pbo).getContainer();
    if (VERBOSE) {
      System.out.println("        &&&&DEBUG:      container = " + container.getName());
    }

    boolean flag = SessionServerHelper.manager.setAccessEnforced(false);

    ContainerTeam containerTeam = ContainerTeamHelper.service.getContainerTeam((ContainerTeamManaged)container);
    ContainerTeam shareContainerTeam = null;
    ContainerTeamReference containerRef = ((ContainerTeamManaged)container).getSharedTeamReference();
    if (containerRef != null)
    {
      shareContainerTeam = (ContainerTeam)containerRef.getObject();
      if (VERBOSE) {
        System.out.println("    got share team=" + shareContainerTeam.getName());
      }
    }
    Role role = Role.toRole(roleName);
    ArrayList participants = containerTeam.getAllPrincipalsForTarget(role);
    if (participants != null) {
      for (int j = 0; j < participants.size(); j++)
      {
        WTPrincipal wtp = ((WTPrincipalReference)participants.get(j)).getPrincipal();
        if (VERBOSE)
          System.out.println("    local team----add the principal(" + wtp.getName() + " into the role " + roleName);
        addUser(participants1, wtp);
      }
    }

    if (shareContainerTeam != null)
    {
      if (VERBOSE)
        System.out.println("    开始处理共享团队.");
      ArrayList participants2 = shareContainerTeam.getAllPrincipalsForTarget(role);
      if (participants2 != null)
        for (int j = 0; j < participants2.size(); j++)
        {
          WTPrincipal wtp = ((WTPrincipalReference)participants2.get(j)).getPrincipal();
          if (VERBOSE)
            System.out.println("    share team------  add the principal(" + wtp.getName() + " into the role " + roleName);
          addUser(participants1, wtp);
        }
      if (VERBOSE)
        System.out.println("    结束处理共享团队.");
    }
    SessionServerHelper.manager.setAccessEnforced(flag);
    if (VERBOSE)
      System.out.println("<<<" + CLASSNAME + ".addRoleUser1()---role name=" + roleName);
  }

  private void addGroupUser1(Vector participants, String groupName)
    throws QueryException, WTException
  {
    WTGroup wtgroup = getGroupByName(groupName);
    if (wtgroup != null)
    {
      Enumeration members = wtgroup.members();
      while ((members != null) && (members.hasMoreElements()))
      {
        WTPrincipal wtp = (WTPrincipal)members.nextElement();
        addUser(participants, wtp);
      }
    }
  }

  private void addUser(Vector participants, WTPrincipal wtp)
    throws WTException
  {
    if (((wtp instanceof WTUser)) && (!participants.contains(wtp)))
      participants.add(wtp);
    if ((wtp instanceof WTGroup))
    {
      Enumeration members = ((WTGroup)wtp).members();
      while ((members != null) && (members.hasMoreElements()))
      {
        WTPrincipal wtp1 = (WTPrincipal)members.nextElement();
        addUser(participants, wtp1);
      }
    }
  }

  private WTGroup getGroupByName(String groupName)
    throws QueryException, WTException
  {
    WTGroup wtgroup = null;
    QuerySpec qs = null;
    QueryResult qr = null;
    qs = new QuerySpec(WTGroup.class);
    SearchCondition sc = new SearchCondition(WTGroup.class, "name", "=", groupName);
    qs.appendSearchCondition(sc);
    qr = PersistenceHelper.manager.find(qs);
    if (qr.hasMoreElements())
    {
      wtgroup = (WTGroup)qr.nextElement();
    }

    return wtgroup;
  }

  public static Vector parseRoleStr(String augmentRolesStr)
  {
    Vector v = new Vector();
    StringTokenizer st = new StringTokenizer(augmentRolesStr, ";;;qqq");
    while (st.hasMoreTokens())
    {
      v.addElement(st.nextToken());
    }
    if (VERBOSE)
      System.out.println("        &&&&DEBUG:      v = " + v.size());
    return v;
  }

  public String augmentPartApplyRolesSelects(String oid)
    throws Exception
  {
    return null;
  }
}